package cc.telecomdigital.tdstock.trading.Common;

import java.util.ArrayList;
import java.util.List;

import android.os.Parcel;
import android.os.Parcelable;

public class Trade_StockHistItem implements Parcelable
{
	public String		stockCode;
	public String		chnName;
	public String		engName;
	public String		lastClosePrice;

	public String		orderNo;
	public String		price;
	public String		orderType;		// E of enhance
	public String		orderSide;		// B=Bid, A=Ask
	public String		quantity;
	public String		channel;
	public String		orderTime;
	public String       currencyCode;
	public String		statusCode;
	public String		statusName;
	public String		fillQuantity;
	public String		cancelQuantity;
	public String		outstandQuantity;
	public List<String>	details;

	/** Stock History Item is the order being placed in the server before.
	 * 	
	    Use under Get Multiple Order and StockOrder Detail **/
	
	/** Stock History item is the order being placed in the serve before
	  *  Use under Get Multiple Order and StockOrder Detail
	  *  @param iCode  = stock code representative
	  *  @param iChnName = chine title
	  *  @param iEngName = eng title
	  *  @param iLastPrice = last close price
	  *  @param iCurrency = currency type	
	 */
	public Trade_StockHistItem(String iCode, String iChnName, String iEngName,
			String iLastPrice, String iCurrencyCode)
	{
		stockCode = iCode;
		chnName = iChnName;
		engName = iEngName;
		lastClosePrice = iLastPrice;
		currencyCode = iCurrencyCode;
		details = new ArrayList<String>();
	}

	/** Place in the obtained info from Server **/
	public void SetReqOrderInfo(String iOrderNo, String iReqPrice,
			String iOrderType, String iOrderSide, String iQuantity,
			String iChannel, String iTimeStamp)
	{
		orderNo = iOrderNo;
		price = iReqPrice;
		orderType = iOrderType;
		orderSide = iOrderSide;
		quantity = iQuantity;
		channel = iChannel;
		orderTime = iTimeStamp;
	}

	/** Place in the obtained info from Server **/	
	public void SetProcessOrderInfo(String iStatusCode, String iStatusName,
			String iFillQuantity, String iCancelQuantity,
			String iOutStandQuantity)
	{
		statusCode = iStatusCode;
		statusName = iStatusName;
		fillQuantity = iFillQuantity;
		cancelQuantity = iCancelQuantity;
		outstandQuantity = iOutStandQuantity;
	}

	/** Extra inforamtion from server, such as text **/	
	public void AppendProcessDetail(String iInfo)
	{
		details.add(iInfo);
	}

	static private int parcelStringMember = 17;
	/** Parcel-able function call **/
	@Override
	public void writeToParcel(Parcel out, int iFlag)
	{
		// Write has the same sequence of read
		out.writeStringArray(new String[]{ stockCode, chnName, engName,
									lastClosePrice, currencyCode, orderNo,
									price, orderType, orderSide,
									quantity, channel, orderTime,
									statusCode, statusName, fillQuantity,
									cancelQuantity, outstandQuantity
								   });
		
//		out.writeString(stockCode);
//		out.writeString(chnName);
//		out.writeString(engName);
//		out.writeString(lastClosePrice);
//		out.writeString(currencyCode);		
//		out.writeString(orderNo);
//		out.writeString(price);
//		out.writeString(orderType);
//		out.writeString(orderSide);
//		out.writeString(quantity);
//		out.writeString(channel);
//		out.writeString(orderTime);
//
//		out.writeString(statusCode);
//		out.writeString(statusName);
//		out.writeString(fillQuantity);
//		out.writeString(cancelQuantity);
//		out.writeString(outstandQuantity);
		out.writeList(details);
	}

	public static final Parcelable.Creator<Trade_StockHistItem>	CREATOR	= new Parcelable.Creator<Trade_StockHistItem>()
															{
																public Trade_StockHistItem createFromParcel(
																		Parcel in)
																{
																	return new Trade_StockHistItem(
																			in);
																}

																public Trade_StockHistItem[] newArray(
																		int size)
																{
																	return new Trade_StockHistItem[size];
																}
															};
	/** Set the object as Parcel item to be placed in a bundle package **/
	private Trade_StockHistItem(Parcel in)
	{
		String[] inStrArray;
		
		inStrArray = new String[parcelStringMember];	
		in.readStringArray(inStrArray);
		
		stockCode = inStrArray[0];
		chnName = inStrArray[1];
		engName = inStrArray[2];
		lastClosePrice = inStrArray[3];
		currencyCode = inStrArray[4];	
		orderNo = inStrArray[5];
		price = inStrArray[6];
		orderType = inStrArray[7];
		orderSide = inStrArray[8];
		quantity = inStrArray[9];
		channel = inStrArray[10];
		orderTime = inStrArray[11];

		statusCode = inStrArray[12];
		statusName = inStrArray[13];
		fillQuantity = inStrArray[14];
		cancelQuantity = inStrArray[15];
		outstandQuantity = inStrArray[16];

		if (details != null)
			details.clear();
		
		details = new ArrayList<String>();
		in.readList(details, null);
	}
	
	@Override
	public int describeContents()
	{
		return 0;
	}
}
